package com.word.teacher.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.word.common.annotation.Log;
import com.word.common.enums.BusinessType;
import com.word.teacher.domain.WordGroupDict;
import com.word.teacher.service.IWordGroupDictService;
import com.word.common.core.controller.BaseController;
import com.word.common.core.domain.AjaxResult;
import com.word.common.utils.poi.ExcelUtil;
import com.word.common.core.page.TableDataInfo;

/**
 * 单词分组管理Controller
 * 
 * @author wsccvb
 * @date 2025-07-18
 */
@Controller
@RequestMapping("/teacher/dict")
public class WordGroupDictController extends BaseController
{
    private String prefix = "teacher/dict";

    @Autowired
    private IWordGroupDictService wordGroupDictService;

    @RequiresPermissions("teacher:dict:view")
    @GetMapping()
    public String dict()
    {
        return prefix + "/dict";
    }

    /**
     * 查询单词分组管理列表
     */
    @RequiresPermissions("teacher:dict:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WordGroupDict wordGroupDict)
    {
        startPage();
        List<WordGroupDict> list = wordGroupDictService.selectWordGroupDictList(wordGroupDict);
        return getDataTable(list);
    }

    /**
     * 导出单词分组管理列表
     */
    @RequiresPermissions("teacher:dict:export")
    @Log(title = "单词分组管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WordGroupDict wordGroupDict)
    {
        List<WordGroupDict> list = wordGroupDictService.selectWordGroupDictList(wordGroupDict);
        ExcelUtil<WordGroupDict> util = new ExcelUtil<WordGroupDict>(WordGroupDict.class);
        return util.exportExcel(list, "单词分组管理数据");
    }

    /**
     * 新增单词分组管理
     */
    @RequiresPermissions("teacher:dict:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存单词分组管理
     */
    @RequiresPermissions("teacher:dict:add")
    @Log(title = "单词分组管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WordGroupDict wordGroupDict)
    {
        return toAjax(wordGroupDictService.insertWordGroupDict(wordGroupDict));
    }

    /**
     * 修改单词分组管理
     */
    @RequiresPermissions("teacher:dict:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WordGroupDict wordGroupDict = wordGroupDictService.selectWordGroupDictById(id);
        mmap.put("wordGroupDict", wordGroupDict);
        return prefix + "/edit";
    }

    /**
     * 修改保存单词分组管理
     */
    @RequiresPermissions("teacher:dict:edit")
    @Log(title = "单词分组管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WordGroupDict wordGroupDict)
    {
        return toAjax(wordGroupDictService.updateWordGroupDict(wordGroupDict));
    }

    /**
     * 删除单词分组管理
     */
    @RequiresPermissions("teacher:dict:remove")
    @Log(title = "单词分组管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wordGroupDictService.deleteWordGroupDictByIds(ids));
    }
}
